home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Sample Extensions (1.5) / MacCough ƒ / TM Task.c < prev   
C/C++ Source or Header  |  1995-11-01  |  3KB  |  140 lines

  1. /*    NAME:
  2.         TM Task.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a code resource to be installed as a Time Manager
  9.         task.
  10.  
  11.     NOTES:
  12.         We fire every 10 seconds, and install a Notification Manager request
  13.         that plays a sound.
  14.  
  15.     ___________________________________________________________________________
  16. */
  17. //=============================================================================
  18. //        Include files                                                                     
  19. //-----------------------------------------------------------------------------
  20. #include <Gestalt.h>
  21. #include <Notification.h>
  22. #include <Timer.h>
  23. #include "A4Stuff.h"
  24. #include "SetupA4.h"
  25. #include "MC Constants.h"
  26. #include "MC AddrsTable.h"
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. //=============================================================================
  43. //        Global Variables                                                                 
  44. //-----------------------------------------------------------------------------
  45. TMTask                *gTheTMTask;
  46. NMRec                gTheNMRec;
  47. Boolean                gAlreadyRan = false;
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. //=============================================================================
  64. //        Private function prototypes                             
  65. //-----------------------------------------------------------------------------
  66. pascal void        main(void);
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. //=============================================================================
  83. //        main : Entry point to our code resource.                                                                 
  84. //-----------------------------------------------------------------------------
  85. //        Note :    We install a Notification Manager request which plays the
  86. //                sound, and reschedule ourselves for 10 seconds from now.
  87. //-----------------------------------------------------------------------------
  88. pascal void main(void)
  89. {    long                oldA4;
  90.     MCAddressTable        *theAddressTable;
  91.     OSErr                theErr;    
  92.  
  93.  
  94.  
  95.     // Set up A4
  96. #ifndef powerc
  97.     oldA4 = SetCurrentA4();
  98. #endif
  99.     
  100.     
  101.     
  102.     // If we've not already been called, call the Gestalt selector to get
  103.     // the address of our task record, and create our Notification
  104.     // Manager record.
  105.     if (!gAlreadyRan)
  106.         {
  107.         // Call gestalt and get the address of our task
  108.         Gestalt(kMacCoughAddressTable, (long *) &theAddressTable);        
  109.         gTheTMTask = (TMTask *) ((long) theAddressTable->theTable[kTimeTask]);
  110.         
  111.         
  112.         // Make up a Notification Manager request
  113.         gTheNMRec.qType        = nmType;                        // NM request type
  114.         gTheNMRec.nmMark    = 0;                            // No mark in the menu
  115.         gTheNMRec.nmIcon    = nil;                            // No icon in the menu
  116.         gTheNMRec.nmSound    = theAddressTable->theSound;    // Play this sound
  117.         gTheNMRec.nmStr        = nil;                            // Don't show a dialog
  118.         gTheNMRec.nmResp    = (NMUPP) -1;                    // Remove the note afterwards
  119.         
  120.         
  121.         // This code doesn't need to be executed again
  122.         gAlreadyRan = true;
  123.         }
  124.     
  125.  
  126.     
  127.     // Install the Notification Manager request (which plays
  128.     // the sound) and requeue ourselves for 10 seconds from now.
  129.     theErr = NMInstall(&gTheNMRec);
  130.     PrimeTime((QElemPtr) gTheTMTask, 10000);
  131.  
  132.  
  133.  
  134.     // Restore A4 and return
  135. #ifndef powerc
  136.     SetA4(oldA4);
  137. #endif
  138. }
  139.  
  140.